import { formatTimeToStr } from '@/utils/date'

export const formatDate = (time) => {
  if (time !== null && time !== '') {
    var date = new Date(time)
    return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
  } else {
    return ''
  }
}

export const formatDay = (time) => {
  if (time !== null && time !== '') {
    var date = new Date(time)
    return formatTimeToStr(date, 'yyyy-MM-dd')
  } else {
    return ''
  }
}

export const filterDict = (value, options) => {
  const rowLabel = options && options.filter(item => item.value === value)
  return rowLabel && rowLabel[0] && rowLabel[0].label
}

export const formatEncryPhone = (phone) => {
  phone = '' + phone;
  let reg=/(\d{3})\d{4}(\d{4})/;
  return phone.replace(reg, "$1****$2")
}

export const cinccFilterTime = (val) => {
  let h = parseInt(val/3600)
  h = h>9?`${h}`:`0${h}`
  let m = parseInt((val-3600*h)/60)
  m = m>9?`${m}`:`0${m}`
  let s = val-3600*h-60*m
  s = s>9?`${s}`:`0${s}`
  return `${h}:${m}:${s}`
}